/*!***************************************************
 * @file: func.c
 * @brief: 实现好友和通信功能的头文件
 * @author: ITHAO 
 * @date: 2018.12.11
 * @note: 
 ****************************************************/
#ifndef __FUNC_H__
#define __FUNC_H__

#include <stdbool.h>
#include <time.h>

#include "list.h"


#define CHAT_HISTROY_FILE   "./log/histroy/"

#define NAME_MAX_LENGTH     11
#define ACCOUNT_MAX_LENGTH  11
#define MSG_MAX_LENGTH (65535-48-3)

#ifndef TRUE 
#define TRUE    1
#endif
#define FAIL    0
/*好友信息*/
struct friend_info {
    bool online_flag;
    char name[NAME_MAX_LENGTH];
    char account[ACCOUNT_MAX_LENGTH];
};

/*一个好友的链表项*/
struct friend {
    struct friend_info info;
    struct list_head list;
};

/*聊天包*/
struct chat_packet {
    char *send_name;
    char *send_account;
    char *recv_account;
    char *send_time;
    char *msg;
};

extern bool add_friend_to_list(struct list_head *friend_list_head,
                                struct friend_info info);
extern bool remove_friend_from_list(struct list_head *friend_list_head,
                                    char *friend_account);
extern void device_destroy_friend_list(struct list_head *friend_list_head);

extern bool change_friend_online_flag(char *friend_account, bool status,
                                    struct list_head *friend_list_head);                
extern void save_chat_history(struct chat_packet chat_packet,
                              bool sender_or_recver);

extern bool get_chat_histroy(struct chat_packet *p_chat_packet,
                             unsigned int packet_num);
#endif